/**
 * @author Aaron
 * @createTime 15:28 2022/6/3
 **/
package services

import (
	"fmt"
	"github.com/jinzhu/copier"
	"longmen/server/pkg/common/api_models"
	"longmen/server/pkg/common/helper/const"
	utils2 "longmen/server/pkg/common/helper/util"
	"longmen/server/pkg/db/mysql/db_main"
)

func (s *Service) GetActivityRewardById(id int) (*api_models.ActivityReward, error) {
	ar := &api_models.ActivityReward{}

	rewardList, err := db_main.GetActivityReward(id) //活动奖励数据
	if err != nil {
		return nil, err
	}

	for _, reward := range rewardList {
		destGift := &api_models.ActivityGift{}
		destProp := &api_models.Prop{}

		switch _const.RewardType(reward.RewardType) {
		case _const.REWARD_TYPE_GIFT:
			err := copier.Copy(destGift, reward)
			if err != nil {
				return nil, fmt.Errorf("%s%s", utils2.Convert2(), err.Error())
			}
			ar.Gift = append(ar.Gift, destGift)
		case _const.REWARD_TYPE_PROP:
			err := copier.Copy(destProp, reward)
			if err != nil {
				return nil, fmt.Errorf("%s%s", utils2.Convert2(), err.Error())
			}
			ar.Prop = append(ar.Prop, destProp)
		}
	}

	return ar, nil
}
